-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Recommit "[ConstraintElim] Simplify cmp after uadd.sat/usub.sat (#135603)" #136467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
el-ev
wants to merge
1
commit into
users/el-ev/04-18-_constraintelim_fix_poison_check_before_adding_intrinsic_facts
Choose a base branch
from
users/el-ev/04-20-_recommit_constraintelim_simplify_cmp_after_uadd.sat_usub.sat_135603_
base: users/el-ev/04-18-_constraintelim_fix_poison_check_before_adding_intrinsic_facts
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-llvm-transforms Author: Iris (el-ev) ChangesFull diff: https://github.com/llvm/llvm-project/pull/136467.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index 8684420b73671..9fd6b067debdf 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -1139,6 +1139,8 @@ void State::addInfoFor(BasicBlock &BB) {
// when simplifying uses of the min/max intrinsics.
[[fallthrough]];
case Intrinsic::abs:
+ case Intrinsic::uadd_sat:
+ case Intrinsic::usub_sat:
if (!isGuaranteedNotToBePoison(&I))
break;
WorkList.push_back(FactOrCheck::getInstFact(DT.getNode(&BB), &I));
@@ -1896,6 +1898,20 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT, LoopInfo &LI,
AddFact(Pred, MinMax, MinMax->getRHS());
continue;
}
+ if (auto *USatI = dyn_cast<SaturatingInst>(CB.Inst)) {
+ switch (USatI->getIntrinsicID()) {
+ default:
+ llvm_unreachable("Unexpected intrinsic.");
+ case Intrinsic::uadd_sat:
+ AddFact(ICmpInst::ICMP_UGE, USatI, USatI->getLHS());
+ AddFact(ICmpInst::ICMP_UGE, USatI, USatI->getRHS());
+ break;
+ case Intrinsic::usub_sat:
+ AddFact(ICmpInst::ICMP_ULE, USatI, USatI->getLHS());
+ break;
+ }
+ continue;
+ }
}
Value *A = nullptr, *B = nullptr;
diff --git a/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll b/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll
index 42bbe67024e58..c19a0548d78b2 100644
--- a/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll
+++ b/llvm/test/Transforms/ConstraintElimination/uadd-usub-sat.ll
@@ -8,9 +8,7 @@ define i1 @uadd_sat_uge(i64 noundef %a, i64 noundef %b) {
; CHECK-LABEL: define i1 @uadd_sat_uge(
; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) {
; CHECK-NEXT: [[ADD_SAT:%.*]] = call i64 @llvm.uadd.sat.i64(i64 [[A]], i64 [[B]])
-; CHECK-NEXT: [[CMP1:%.*]] = icmp uge i64 [[ADD_SAT]], [[A]]
-; CHECK-NEXT: [[CMP2:%.*]] = icmp uge i64 [[ADD_SAT]], [[B]]
-; CHECK-NEXT: [[CMP:%.*]] = and i1 [[CMP1]], [[CMP2]]
+; CHECK-NEXT: [[CMP:%.*]] = and i1 true, true
; CHECK-NEXT: ret i1 [[CMP]]
;
%add.sat = call i64 @llvm.uadd.sat.i64(i64 %a, i64 %b)
@@ -24,8 +22,7 @@ define i1 @usub_sat_ule_lhs(i64 noundef %a, i64 noundef %b) {
; CHECK-LABEL: define i1 @usub_sat_ule_lhs(
; CHECK-SAME: i64 noundef [[A:%.*]], i64 noundef [[B:%.*]]) {
; CHECK-NEXT: [[SUB_SAT:%.*]] = call i64 @llvm.usub.sat.i64(i64 [[A]], i64 [[B]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp ule i64 [[SUB_SAT]], [[A]]
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%sub.sat = call i64 @llvm.usub.sat.i64(i64 %a, i64 %b)
%cmp = icmp ule i64 %sub.sat, %a
|
dtcxzyw
approved these changes
Apr 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.